<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/common/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/global.css">
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="hidden" name="id" class="layui-input id">
            <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label">年龄</label>
        <div class="layui-input-inline">
            <input type="text" name="age" placeholder="请输入年龄" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-inline">
            <input type="text" name="code" required lay-verify="required" disabled placeholder="请输入账号"
                   autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline" style="width: 200px !important;">
            <input type="radio" name="sex" value="male" title="男">
            <input type="radio" name="sex" value="female" title="女">
            <input type="radio" name="sex" value="secrecy" title="保密">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required|pass" placeholder="请输入密码"
                   autocomplete="off"
                   class="layui-input password">
        </div>
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
            <input type="password" name="confirmPassword" required lay-verify="repass" placeholder="请再次输入密码"
                   autocomplete="off"
                   class="layui-input password">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">院校</label>
        <div class="layui-input-inline">
            <input type="text" name="graduateSchool" placeholder="请输入毕业院校" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label">学历</label>
        <div class="layui-input-inline">
            <select name="degree">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" style="width: ">
        <label class="layui-form-label">小组</label>
        <div class="layui-input-block">
            <select name="teamId">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-inline">
            <input type="text" name="phone" required lay-verify="required" placeholder="请输入手机号" autocomplete="off"
                   class="layui-input">
        </div>
        <label class="layui-form-label">住址</label>
        <div class="layui-input-inline">
            <input type="text" name="address" placeholder="请输入住址" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">头像</label>
        <div class=" layui-input-block layui-upload">
            <button type="button" class="layui-btn" id="upload_btn">上传图片</button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="showImg">
                <p id="backText"></p>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">封禁</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formSubmit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script src="/common/layui/layui.js"></script>
<script src="/js/global.js"></script>
<script>
    layui.use(['form', 'jquery'], function () {
        upload("#upload_btn", "/admin/upload");
        let form = layui.form, $ = layui.jquery
        form.verify({
            pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ],
            repass: (value, item) => {
                if (value !== $("input[name='password']").val()) {
                    return "两次输入的密码不一致";
                }
            }
        });
        form.on('submit(formSubmit)', function (data) {
            let succeedUploadPath = sessionStorage.getItem("succeedUploadPath");
            if (!isEmpty(succeedUploadPath)) {
                data.field.headImg = JSON.parse(succeedUploadPath)[0];
                sessionStorage.removeItem("succeedUploadPath");
            }
            data.field.status = isEmpty(data.field.status) ? "normal" : "banned";
            let params = filterFormOnNull(data.field);
            ajax("/admin/user/update", "POST", params, (res) => {
                let icon = 2;
                if (res.code === 0) {
                    icon = 1;
                    parent.layui.table.reload("userTable");
                    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
                parent.layer.msg(res.msg, {icon: icon, offset: 'rt'});
            });
            return false;
        });
    });
</script>
</html>